#include "StringUtil.h"



CStringUtil::CStringUtil()
{
}


CStringUtil::~CStringUtil()
{
}

int CStringUtil::Spilt(const string &stSrcString, vector<string> &vecSubString, const string &stSeparator, bool bKeepEmptyString)
{
    if (stSrcString.empty() || stSeparator.empty())
    {
        return 0;
    }

    int iCount = 0;


    int iBegin = 0;
    int iEnd = 0;
    string sSubString;


    while (iEnd != string::npos && iBegin < stSrcString.length())
    {
        iEnd = stSrcString.find_first_of(stSeparator, iBegin);

        if (iEnd == string::npos)
        {
            sSubString = stSrcString.substr(iBegin, string::npos);
        }
        else
        {
            sSubString = stSrcString.substr(iBegin, iEnd - iBegin);
        }

        if (!sSubString.empty() || bKeepEmptyString)
        {
            vecSubString.push_back(sSubString);
            ++iCount;
        }
        iBegin = iEnd + 1;
    }
    return iCount;
}
